home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RGBBufferToGrayPatch.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains C code for the patch version of the
- RGBBufferToGray operator.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1993-1997 by Apple Computer, Inc., all rights reserved.
- */
-
-
- #include "printer types.h"
-
- void RGBBufferToGray()
- {
-
- StringObj *rgbString;
- unsigned char *p, *pGrey; // Pointer into string data.
- long r, g, b, grey;
- long i, nPix;
-
-
- ps_dup(); // Duplicate the string on the stack for getinterval later.
- rgbString = PopString(); // Get a reference to the string object.
-
- nPix = rgbString->length / 3; // Compute the number of pixels.
- p = rgbString->strptr;
- pGrey = p;
-
- for (i = 0; i < nPix; ++i) {
-
- r = *p++;
- g = *p++;
- b = *p++;
-
- /** This computes (5*red + 9*green + 2*blue)/16 **/
-
- // ((((((r+g)/2)+b)/2+r)/2)+g)/2
- grey = ( ( ( (( ( (r+g) >> 1) + b) >> 1) + r) >> 1) +g ) >> 1;
-
- *pGrey++ = grey; // Write it back into the string at position i.
-
- }//end for
-
-
- /** Now put the substring [0…nPix-1] on stack **/
-
- PushLong(0);
- PushLong(nPix);
- ps_getinterval();
-
- }//RGBBufferToGray
-
-
-
- void DefineCommand()
- {
- RegisterCommand("RGBBufferToGray", RGBBufferToGray);
- }
-